package com.hongye.app.model;

import java.util.List;

import com.hongye.util.Utils;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
/**
 * 员工管理相关
 * @author Administrator
 *
 */
public class EmployeeManageModel extends Model<EmployeeManageModel>{

	private static final long serialVersionUID = 1L;
	
	public static final EmployeeManageModel dao = new EmployeeManageModel();
	
	/**
	 * 获取所有员工信息
	 * @author lifuqiang
	 * 2017-3-20
	 * @return
	 */
	public List<EmployeeManageModel> getEmployeeList(){
		String sql = "select * from employee_manage order by c_time desc";
		List<EmployeeManageModel> list = dao.find(sql);
		return list;
	}

	/**
	 * 根据员工邀请码 获取员工
	 * @author liushaomin
	 * 2017年3月20日
	 * @param employee_invite_code
	 * @return
	 */
	public static EmployeeManageModel getByEmployee_invite_code(String employee_invite_code) {
		String sql = "select * from employee_manage where employee_num = '"+employee_invite_code+"'";
		return dao.findFirst(sql);
	}
	
	/**
	 * 根据员工邀请码判断员工是否存在
	 * @author lifuqiang
	 * 2017-3-21
	 * @param employee_invite_code
	 * @return
	 */
	public static boolean isExistEmployee(String employee_invite_code) {
		List<Record> list = Db.find("select * from employee_manage where employee_num = '"+employee_invite_code+"'");
		boolean isExist = false;
		if(list.size() > 0){
			isExist = true;
		}
		return isExist;
	}
	
	/**
	 * 添加新员工
	 * @author lifuqiang
	 * 2017-3-20
	 * @param department
	 * @param place
	 * @param e_name
	 * @param e_sex
	 * @param e_phone
	 * @param employee_num
	 * @return
	 */
	public boolean addNewEmployee(int department, String place, String e_name, int e_sex, String e_phone, String employee_num){
		Record employee = new Record().set("department", department).set("place", place).set("e_name", e_name).set("e_sex", e_sex).set("e_phone", e_phone)
					.set("employee_num", employee_num).set("status", 0).set("c_time", Utils.getDate());
		return Db.save("user", employee);
	}
	
	/**
	 * 修改员工信息（修改状态）
	 * @author lifuqiang
	 * 2017-4-21
	 * @param id
	 * @param status
	 */
	public static void update(String id, String status){
		Db.update("update employee_manage set status = ? where e_id = ?", status,id);
	}
	
}
